/**
 * 
 */
package com.acminds.fotoporter.service.client;

import com.acminds.fotoporter.exceptions.AuthenticationFailureException;
import com.acminds.fotoporter.persistence.dao.UserInfoDAO;
import com.acminds.fotoporter.persistence.dto.UserInfo;
import com.acminds.fotoporter.service.BaseService;
import com.acminds.fotoporter.utils.Utils;

/**
 * @author MANSUR
 *
 */
public class UserInfoService extends BaseService {
	
	private UserInfoDAO userInfoDao;
	public UserInfoDAO getUserInfoDao() {
		return userInfoDao;
	}
	public void setUserInfoDao(UserInfoDAO userInfoDao) {
		this.userInfoDao = userInfoDao;
	}


	public UserInfo findUser(String userName, String password) {
		UserInfo userInfo = getUserInfoDao().findUser(userName, password);
		if(userInfo==null)
			throw new AuthenticationFailureException();
		userInfo.setLastLoginDate(Utils.today());
		getDefaultDAO().save(userInfo, true);
		return userInfo;
	}
	
	public void saveUser(UserInfo userInfo) {
		getDefaultDAO().save(userInfo, false);
		getDefaultDAO().saveAll(userInfo.getLocations(), true);
	}

}
